package com.example.demo.servlet;

import com.example.demo.dao.CartDao;
import com.example.demo.entity.CartVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/updatecart")
public class UpdateCartServlet extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CartVo cart=new CartVo();
        cart.setCartId(Integer.valueOf(req.getParameter("id")));
        cart.setQuantity(Integer.valueOf(req.getParameter("Quantity")));
        cart.setBookId(Integer.valueOf(req.getParameter("BookId")));
        cart.setUserId(Integer.valueOf(req.getParameter("UserId")));
        try {
            new CartDao().updateCart(cart);
            req.getRequestDispatcher("/category/list").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }

    }
}

